using System;
using System.IO;
using System.Web.UI;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace ASPNETVN.PORTAL.Modules.XML
{
    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            ModuleSettingItem xmlSource = new ModuleSettingItem(new StringDataType());
            xmlSource.Name = "Xml source file";
            xmlSource.Order = 0;
            this.BaseSettings.Add("XmlSource", xmlSource);

            ModuleSettingItem XslSource = new ModuleSettingItem(new StringDataType());
            XslSource.Name = "Xsl Source file";
            XslSource.Order = 1;
            this.BaseSettings.Add("XslSource", XslSource);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            StringDataType xmlSource = new StringDataType();
            xmlSource.Value = Settings["XmlSource"].ToString();

            if (!string.IsNullOrEmpty(xmlSource.Value))
            {
                if (File.Exists(Server.MapPath(xmlSource.Value)))
                {
                    xml1.DocumentSource = Server.MapPath(xmlSource.Value);
                }
                else
                {
                    Controls.Add(new LiteralControl("<br>" + "<span class='Error'>File not found " + xmlSource.Value + "<br>"));
                }
            }

            StringDataType xslSource = new StringDataType();
            xslSource.Value = Settings["XslSource"].ToString();

            if (!string.IsNullOrEmpty(xslSource.Value))
            {
                if (File.Exists(Server.MapPath(xslSource.Value)))
                {
                    xml1.TransformSource = Server.MapPath(xslSource.Value);
                }
                else
                {
                    Controls.Add(new LiteralControl("<br>" + "<span class='Error'>File not found " + xslSource.Value + "<br>"));
                }
            }
        }
    }
}